# 作者：一只牛吗
# 2025 年01月 22日 04时 01分 27秒
# 1278599690@qq.com
def capitalize_string():
    """
    字符串大写化后，地址会改变
    """
    s1 = "hello world"
    s2 = s1.upper()
    print(s2)
    print(id(s1))
    print(id(s2))


def traversal_string(s):
    """
    遍历字符串，字符串也是可迭代对象
    """
    for c in s:
        print(c, end="|")


def length_string(s):
    """
    计算字符串长度
    """
    print(len(s))
    return len(s)


def count_string(s, c):
    """
    计算字符串中某个字符出现的次数，c是检查的字符，s是字符串，count是计数器
    """
    count = s.count(c)
    print(f'{c}字符在字符串{s}中出现了{count}次。')


def check_type_string(s):
    """
    检查字符串的类型
    """
    print(s.isalnum())


def string_find(s, c):
    '''
    查询字符串中目的字符的位置
    :param s: 被查询字符串
    :param c: 目的字符
    :return:
    '''
    s1 = s.find(c, 0, len(s))
    if s1 == -1:
        print(f'{c}字符不在字符串{s}中。')
    else:
        print(f'{c}字符在字符串{s}中第{s1 + 1}个位置。')
    return s1


def string_replace(s, old, new):
    """
    替换字符串中的字符
    """
    s1 = s.replace(old, new)
    print(s1)
    return s1


def string_split():
    """
    字符串分割
    """
    s1 = 'abc def 我很帅'
    print(s1.split())
    s2 = '1,2,3,4,5'
    print(s2.split(','))
    s3 = '123\n456\n789'
    print(s3.splitlines())
    string_list = ['a', 'b', 'c', 'd', 'e']  # 字符串合并
    print('-'.join(string_list))


def string_to_list():
    """
    字符串转换为列表
    """
    s1 = '0123456789'
    s2 = list(s1)
    print(s2)
    s3 = ''.join(s2)
    print(s3)
    list1 = [int(x) for x in s2]
    print(list1)


if __name__ == '__main__':
    # capitalize_string()
    # traversal_string("hello world")
    # length_string("hello world")
    # count_string("hello world", "l")
    # check_type_string("helloworld")
    # string_find("hello world", "d")
    # string_replace("hello world", "l", "L")
    # string_split()
    num_str = '0123456789'
    # print(num_str[::-1])  # 字符串反转
    # print(num_str[::1])  # 字符串隔位取值
    # print(num_str[0::-1])
    string_to_list()